package com.cast.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.cast.dao.AddressDao;
import com.cast.entity.PageResult;
import com.cast.entity.QueryPageBean;
import com.cast.pojo.Address;
import com.cast.pojo.CheckItem;
import com.cast.service.AddressService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * @项目名称 health
 * @包名 com.cast.service.impl
 * @类名 AddressServiceImpl
 * @作者 lx
 * @时间 2020/3/6 22:18
 * @描述
 */
@Service(interfaceClass = AddressService.class)
@Transactional
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;

    @Override
    public PageResult findByPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage, pageSize);
        Page<Address> address = addressDao.findByPage(queryString);
        long total = address.getTotal();
        List<Address> rows = address.getResult();
        return new PageResult(total, rows);
    }

    @Override
    public void add(Address address) {
        // 新增检查组，操作t_checkgroup表，同时获取这条记录的id
        addressDao.add(address);
    }

    @Override
    public Address findById(Integer id) {
        return addressDao.findById(id);
    }

    @Override
    public void edit(Address address) {
        addressDao.edit(address);
    }

    @Override
    public void deleteById(Integer id) {
        addressDao.deleteById(id);
    }


}
